package com.jiker;

/**
 * @author leo
 * @date 2021/5/31
 */
public class FizzBuzz {
    private static final Integer THREE = 3;
    private static final Integer FIVE = 5;
    private final Integer rawNumber;

    public FizzBuzz(Integer rawNumber) {
        this.rawNumber = rawNumber;
    }

    public static String of(Integer rawNumber) {
        return new FizzBuzz(rawNumber).parse();
    }

    public String parse() {
        String result = "";
        if (canDivideOrContains(THREE)) {
            result += "Fizz";
        }
        if (canDivideOrContains(FIVE)) {
            result += "Buzz";
        }
        return result.isEmpty() ? String.valueOf(rawNumber) : result;
    }

    private Boolean canDivideOrContains(Integer number) {
        return rawNumber % number == 0 || Integer.toString(rawNumber).contains(Integer.toString(number));
    }
}
